from multiprocessing import Pool
import time ,os

from watchfiles.run import start_process


def sub_process(name):
    print(f'当前进程池名称为：{name}, 当前进程池id为：{os.getpid()}, 父进程id为：{os.getppid()}')
    time.sleep(1)


if __name__ == '__main__':
    start = time.time()
    print('父进程开始')
    pool = Pool(3)
    for i in range(10):
        # pool.apply(sub_process,args=(i,)) #执行子进程 同步执行 10秒
        pool.apply_async(sub_process, args=(i,))  # 执行子进程, 异步执行 4秒
    pool.close() #关闭进程池
    pool.join()
    print('parents over')
    end = time.time() - start
    print(end)
